<?php
namespace Admin\Controller;
use Think\Controller;

class BaseController extends Controller {
	public function _initialize(){
		header("Content-Type:text/html;charset=utf-8");
        //echo '=======================================111';
		if(!cookie('adminId')){
			//header("location: ".U('Login/index'));
			redirect(U('Login/index'));
		}else{
			$User=M('User');
			$where['user']=cookie('adminId');
			$account = get_authcode(cookie('adminId'),'DECODE','www.MapleLeaf.com');
			$F=$User->where(" account='".$account."'")->find();
			if(!$F){
                cookie('adminId',null);
				$this->error('账号异常,请重新登录',U('Login/index'));
                //echo '=======================================!$F';
			}else{
				$this->assign("Admin",$F);
				session('User.id',$F[id]);          //设置session
				session('User.name',$F[nickname]);  //设置session
				session('User.depid',$F[depid]);    //设置session
				session('User.pid',$F[pid]);    //设置session
// 				echo $F[depid].'============<br>';
// 				echo $F[nickname].'============<br>';
// 				echo $F[id].'============<br>';
// 				echo $F[depid].'============<br>';
                //echo '=====================================$F'.$F;
			    //echo $_SERVER["REQUEST_URI"];
			    /*****************************权限过滤**********************************/
			    $menunum = M('Menuright')->field('count(*) as count')
			    ->join('INNER JOIN bs_Menu b ON b.id=bs_Menuright.menuid')
    			->where("'".$_SERVER['REQUEST_URI']."' like CONCAT('%',CONCAT(b.url,'%'))")->find();
			    //echo '<br>===================================================='.$menunum[count];
			    //echo M('Menuright')->getLastSql();
			    if($menunum[count]>0){
			        if(!M('Menuright')
    			    ->join('INNER JOIN bs_Menu b ON b.id=bs_Menuright.menuid')
    			    ->where("'".$_SERVER['REQUEST_URI']."' like CONCAT('%',CONCAT(b.url,'%')) AND bs_Menuright.userid=".$F[id])->find()){
                        $this->display('Help:noright');
                        exit;
			        }
			    }
			    /*****************************权限过滤**********************************/
			}
		}
	}
}